#include<stdlib.h>
#include<stdbool.h>



typedef struct {

    int* a;

    int size;

    int rear;

    int front;

} MyCircularQueue;



bool myCircularQueueIsEmpty(MyCircularQueue* obj) {

    return obj->rear == obj->front;

}



bool myCircularQueueIsFull(MyCircularQueue* obj) {

    return (obj->rear + 1) % (obj->size + 1) == obj->front;

}



MyCircularQueue* myCircularQueueCreate(int k) {

    MyCircularQueue* queue = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));

    queue->a = (int*)malloc((k + 1) * sizeof(int));

    queue->size = k;

    queue->front = queue->rear = 0;

    return queue;

}



bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {

    if (!myCircularQueueIsFull(obj))

    {

        obj->a[obj->rear] = value;

        obj->rear++;

        obj->rear %= (obj->size + 1);

        return true;

    }

    else

    {

        return false;

    }

}



bool myCircularQueueDeQueue(MyCircularQueue* obj) {

    if (myCircularQueueIsEmpty(obj))

    {

        return false;

    }

    else

    {

        obj->front++;

        obj->front %= (obj->size + 1);

        return true;

    }

}



int myCircularQueueFront(MyCircularQueue* obj) {

    if (myCircularQueueIsEmpty(obj))

    {

        return -1;

    }

    else

    {

        return obj->a[obj->front];

    }

}



int myCircularQueueRear(MyCircularQueue* obj) {

    if (myCircularQueueIsEmpty(obj))

    {

        return -1;

    }

    else

    {

        return obj->a[(obj->rear + obj->size) % (obj->size + 1)];

    }

}





void myCircularQueueFree(MyCircularQueue* obj) {

    free(obj->a);

    obj->rear = 0;

    obj->front = 0;

    obj->size = 0;

    free(obj);

}



/**

 * Your MyCircularQueue struct will be instantiated and called as such:

 * MyCircularQueue* obj = myCircularQueueCreate(k);

 * bool param_1 = myCircularQueueEnQueue(obj, value);



 * bool param_2 = myCircularQueueDeQueue(obj);



 * int param_3 = myCircularQueueFront(obj);



 * int param_4 = myCircularQueueRear(obj);



 * bool param_5 = myCircularQueueIsEmpty(obj);



 * bool param_6 = myCircularQueueIsFull(obj);



 * myCircularQueueFree(obj);

*/